package com.usian.search.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.search.dtos.UserSearchDto;
import com.usian.model.search.pojos.ApAssociateWords;
import com.usian.search.mapper.ApAssociateWordsMapper;
import com.usian.search.service.ApAssociateWordsService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class ApAssociateWordsServiceImpl extends ServiceImpl<ApAssociateWordsMapper, ApAssociateWords> implements ApAssociateWordsService {
    @Override
    public ResponseResult search(UserSearchDto dto) {
        //1.检查数据
        if(dto==null || dto.getPageSize() < 0 || dto.getPageNum() < 0 || StringUtils.isBlank(dto.getSearchWords())){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //2.模糊查询数据
        IPage page = new Page(dto.getPageNum(), dto.getPageSize());
        IPage result = this.page(page, Wrappers.<ApAssociateWords>lambdaQuery()
                .like(ApAssociateWords::getAssociateWords, dto.getSearchWords()));
        return ResponseResult.okResult(result.getRecords());
    }
}